package light.head.dao.oa;

import java.util.List;

import org.springframework.stereotype.Service;

import light.head.framework.base.BaseDAO;
import light.head.model.ConsumingDetail;
/***
 * 物品领用（标签）详情
 * @author yy
 *
 */
@Service
public class ConsumingDetailDAO extends BaseDAO<ConsumingDetail, Integer>{
	private final static String sql_findByTag = "FROM ConsumingDetail c WHERE c.tag = ? AND c.deleted = 0";
	private final static String sql_findByTagAndGn = "FROM ConsumingDetail c,ConsumingItem item WHERE c.tag = ? AND c.deleted = 0 AND item.gn = ? AND c.cic = item.code";
	/**
	 * 通过領用信息表的编号获取所有详情
	 * @param ccode 領用信息表编号
	 */
	public List<ConsumingDetail> findByRCode(Integer ccode) {
		if (null == ccode) return null;
		StringBuffer hql = new StringBuffer("FROM ConsumingDetail detail WHERE detail.cic IN (SELECT c.code FROM ConsumingItem c WHERE c.coc = ?)");
		return find(hql.toString(), null, null, ccode);
	}
	
	/**
	 * 
	 */
	public List<ConsumingDetail> findByTag(String tag){
		if(null == tag) return null;
		return find(sql_findByTag, tag);
	}
	
	
	
	
	/**
	 * 通过标签和商品
	 * @param tag
	 * @param gn
	 * @return
	 */
	public List<ConsumingDetail> findByTagAndGn(String tag,String gn){
		if(null == tag || null == gn) return null;
		return find(sql_findByTagAndGn, tag,gn);
	}
}
